﻿using MediatR;
using Yuekao.API.Read.Command;
using Yuekao.Domain.API;
using Yuekao.Domain.BaseReposi;
using Yuekao.Domain.Entitys;

namespace Yuekao.API.Read.CommandHandler
{
    public class GetRejectHandler : IRequestHandler<GetRejectCommandcs, APIPagging<Reject>>
    {
        private readonly IBaseRepository<Reject> rejectRepo;

        public GetRejectHandler(IBaseRepository<Reject> rejectRepo)
        {
            this.rejectRepo = rejectRepo;
        }
        /// <summary>
        /// 审批详情
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIPagging<Reject>> Handle(GetRejectCommandcs request, CancellationToken cancellationToken)
        {
            APIPagging<Reject> res=new APIPagging<Reject>();
            var reject = rejectRepo.GetAll();
            res.Code = APIEnum.Success;
            res.PageData = reject.ToList();
            res.Data = res.PageData.FirstOrDefault(); // 设置Data属性为第一个元素或默认值
            return res;
        }
    }
}
